<template>
  <el-main>
    <el-form status-icon label-width="100px" class="demo-ruleForm">
      <el-form-item label="账号名称">
        <el-input type="loginForm.username" v-model="loginForm.username" autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item label="确认密码" prop="checkPass">
        <el-input type="password" v-model="loginForm.password" autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item label="验证码" prop="checkPass">
        <el-input type="text" v-model="loginForm.code" autocomplete="off"></el-input>
        <img :src="codeImg" width="200px" height="100px" @click="getCode">
      </el-form-item>
      <el-form-item>
        <el-button @click="login()">登录</el-button>
      </el-form-item>
    </el-form>
  </el-main>

</template>

<script>
import { v4 as uuidv4 } from 'uuid';
export default {
  name: "Login",
  data() {
    return {
      loginForm:{
        username:'admin',
        password: '123456'
      },
      searchForm:{

      },
      codeImg: null,

    }
  },
  methods:{
    login() {
      this.axios.get('/auth/user/login', {params: this.loginForm}).then(res => {
        if (res.data.code == 200) {
          // localStorage.setItem("token", res.data.data);
          this.$cookies.set("token", res.data.data);
          this.$router.push('/product');
        }else {
          this.$message.error(res.data.msg);
        }
      }).catch(err=>{
        console.log(err);
      });
    },
    getCode() {
      let uuid = uuidv4();
      this.codeImg = this.axios.defaults.baseURL + "/auth/user/getCode?uuid=" + uuid;
      this.loginForm.uuid = uuid;
    },
  },
  created() {
    this.getCode();
  }
}
</script>

<style scoped>

</style>